package com.ruoyi.project.system.messagenotice.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.messagenotice.domain.MessageNotice;
import com.ruoyi.project.system.messagenotice.service.IMessageNoticeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消息通知公告Controller
 * 
 * @author LCL
 * @date 2021-01-22
 */
@Controller
@RequestMapping("/system/messagenotice")
public class MessageNoticeController extends BaseController
{
    private String prefix = "system/messagenotice";

    @Autowired
    private IMessageNoticeService messageNoticeService;

    @RequiresPermissions("system:messagenotice:view")
    @GetMapping()
    public String messagenotice()
    {
        return prefix + "/messagenotice";
    }

    /**
     * 查询消息通知公告列表
     */
    @RequiresPermissions("system:messagenotice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MessageNotice messageNotice)
    {
        startPage();
        List<MessageNotice> list = messageNoticeService.selectMessageNoticeList(messageNotice);
        return getDataTable(list);
    }

    /**
     * 导出消息通知公告列表
     */
    @RequiresPermissions("system:messagenotice:export")
    @Log(title = "消息通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MessageNotice messageNotice)
    {
        List<MessageNotice> list = messageNoticeService.selectMessageNoticeList(messageNotice);
        ExcelUtil<MessageNotice> util = new ExcelUtil<MessageNotice>(MessageNotice.class);
        return util.exportExcel(list, "messagenotice");
    }

    /**
     * 新增消息通知公告
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存消息通知公告
     */
    @RequiresPermissions("system:messagenotice:add")
    @Log(title = "消息通知公告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MessageNotice messageNotice)
    {
        return toAjax(messageNoticeService.insertMessageNotice(messageNotice));
    }

    /**
     * 修改消息通知公告
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        MessageNotice messageNotice = messageNoticeService.selectMessageNoticeById(id);
        mmap.put("messageNotice", messageNotice);
        return prefix + "/edit";
    }

    /**
     * 修改保存消息通知公告
     */
    @RequiresPermissions("system:messagenotice:edit")
    @Log(title = "消息通知公告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MessageNotice messageNotice)
    {
        return toAjax(messageNoticeService.updateMessageNotice(messageNotice));
    }

    /**
     * 删除消息通知公告
     */
    @RequiresPermissions("system:messagenotice:remove")
    @Log(title = "消息通知公告", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(messageNoticeService.deleteMessageNoticeByIds(ids));
    }
}
